<template>
    <div>
        <el-menu :default-active=activeIndex class="menu" mode="horizontal" background-color="#fff" text-color="#black"
            active-text-color=" rgb(83, 168, 255)" :router="true">

            <div class="menu-left"> <img class="img" src="https://www.ptu.edu.cn/images/logo.png" alt="莆田学院标志"></div>

            <div class="menu-center"><el-menu-item index="/amjHome/frontHome">首页</el-menu-item>
                <el-menu-item index="/amjHome/notice">通知</el-menu-item>
                <el-menu-item index="/amjHome/exam">考试</el-menu-item>
            </div>

            <div class="menu-right">
                <el-avatar class="avatar" :src="userInfoVo.avatar">{{ userInfoVo.name }} </el-avatar>
                <!-- <div class="dropdown">
                    <el-select class="user" :placeholder="userInfoVo.name" size="large" style="width:120px">
                        <el-option value='' class="word">个人中心</el-option>
                        <el-option value='' class="word" @click="toBack">后台管理</el-option>
                        <el-option value='' class="word" @click="logout">退出登录</el-option>
                    </el-select>
                </div> -->
                <div class="dropdown">
                    <a class="user">{{ userInfoVo.name }} <i class="iconfont icon-xiangxia"></i></a>
                    <div class="user-message">
                        <router-link to="/personal" class="word">个人中心</router-link>
                        <router-link to="/adminHome" class="word">后台管理</router-link>
                        <a class="word" @click="logout">退出登录</a>
                    </div>
                </div>

            </div>
        </el-menu>
    </div>
</template>

<script setup>
import { ref, onMounted, } from 'vue';
import { useRouter } from 'vue-router'
import { getUserInfoAPI } from '@/api/api'


const activeIndex = ref('/amjHome/frontHome')

const router = useRouter()
const userInfoVo = ref({
    name: '请登录',
    avatar: '',
})

onMounted(() => {
    getUserInfo()
})

const toBack = () => {
    router.push({
        name: 'backHome'
    })
}


const getUserInfo = async () => {
    await getUserInfoAPI().then(res => {
        if (res.data.code == 200) {
            userInfoVo.value = res.data.data
            sessionStorage.setItem('userName', res.data.data.userName)
        }
    })
}
const logout = async () => {
    localStorage.clear()
    sessionStorage.clear()
    router.push({
        name: 'login'
    })
}

</script>

<style scoped lang="less">
.menu {
    width: 100%;
    height: 60px;
    border: 0;
    position: fixed;
    display: flex;
    justify-content: space-between;
    padding: 0;
    border-bottom: 1px solid rgb(243, 242, 242);
    background: rgb(255, 255, 255);
    background: linear-gradient(0deg, rgba(255, 255, 255, 1) 0%, rgba(203, 222, 246, 1) 100%);
    position: fixed;
    min-width: 100vw;
    // z-index: 100;

    .menu-left {
        width: 20%;
        display: flex;
        justify-content: center;

        .img {
            width: 130px;
            overflow: hidden;
            color: #4a8de0;
            transform: translateY(-200px);
            filter: drop-shadow(0 200px);
        }
    }

    .menu-center {
        display: flex;
        justify-content: center;
    }

    .menu-right {
        width: 20%;
        margin: auto 0;
        display: flex;
        justify-content: center;

        .avatar {
            margin: auto 15px;
        }

        .dropdown {
            margin: auto 0;
            // position: relative;
            display: inline-block;

            .user {
                width: 30px;
                color: black;
                cursor: pointer;
                position: relative;

                svg {
                    width: 10px;
                    height: 10px;
                    margin-left: 3px;
                }
            }

            .user:hover {
                color: rgb(83, 168, 255);
                z-index: 99;

            }

            .user-message {
                display: none;
                position: absolute;
                background-color: #f9f9f9;
                min-width: 100px;
                border-radius: 10px;
                box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
                z-index: 99;
            }

            .word {
                color: black;
                padding: 12px 16px;
                text-decoration: none;
                display: block;
                z-index: 99;

            }
        }

        ::v-deep .el-select__icon {
            position: absolute;
            top: 15px;
            left: -3px;

        }

        ::v-deep .el-select__placeholder {
            color: rgb(103, 103, 103);
            font-size: 15px;
            font-weight: 600;
        }

        ::v-deep .el-select__wrapper {
            border: none;
            box-shadow: none;
            background: rgb(255, 255, 255);
            background: linear-gradient(0deg, rgba(255, 255, 255, 1) 0%, rgba(203, 222, 246, 1) 100%);

        }

        ::v-deep .el-option:hover {
            background-color: rgb(217, 236, 255);
            color: rgb(83, 168, 255);
            border-radius: 10px;
            z-index: 200;
        }

        .dropdown:hover .user-message {
            display: block;
            z-index: 99;

        }

        .user-message .word:hover {
            background-color: rgb(217, 236, 255);
            color: rgb(83, 168, 255);
            border-radius: 10px;
            z-index: 200;
        }
    }
}
</style>
